package main

import main.items.wallet.{TransferMoneyAction, Wallet}
import main.models.World
import main.person.Person
import main.state.State
import main.items.TransferItemAction
import main.items.ball.{Ball, ThrowBallAction}
import main.locations.MoveAction
import main.locations.balaganchik.{Balaganchik, BuyAction}
import main.locations.canteen.Canteen
import main.locations.street.Street

object app extends App {


  val (world, initialState) = State.fromWorld(new World())



  val (balaganchik, state1) = initialState.registerEntity(Balaganchik(name = "шарики", price = 1))
  val (canteen, state2) = state1.registerEntity(Canteen(name = "хавчик", price = 1))

  val state3 = world.addChild(state2, canteen)
  val state4 = world.addChild(state3, balaganchik)

  val (nezn, state5) =  state4.registerEntity(Person("nezn", 10))
  val (kozlik, state6) = state5.registerEntity(Person("kozl", 10))
  lazy val (merchant, state7) = state6.registerEntity(Person("merch", 10))
  val (loli, state8) = state7.registerEntity(Person("loli", 10))

  val state9 = balaganchik.addChild(state8, nezn)
  val state10 = balaganchik.addChild(state9, kozlik)
  val state11 = balaganchik.addChild(state10, merchant)
  val state12 = balaganchik.addChild(state11, loli)

  val (merchantWallet, state13) = state12.registerEntity(Wallet(10))
  val (loliWallet, state14) = state13.registerEntity(Wallet(10))
  val (kozlikWallet, state15) = state14.registerEntity(Wallet(0))

  val state16 = kozlik.addChild(state15, kozlikWallet)
  val state17 = loli.addChild(state16, loliWallet)
  val state18 = merchant.addChild(state17, merchantWallet)

  val state19 = balaganchik.map(state18, a => a.copy(owner = merchant))
  val state20 = canteen.map(state19, a => a.copy(owner = merchant))

  val (ball, state21) = state20.registerEntity(Ball("RED"))
  val state22 = merchant.addChild(state21, ball)
  val state23 = balaganchik.map(state22, a => a.copy(items = a.items :+ ball))

  val state24 = state23(BuyAction(balaganchik, loli, classOf[Ball]))
  val state25 = state24(ThrowBallAction(loli, kozlik, ball))
  val state26 = state25(TransferMoneyAction(merchant, kozlik, 1))

  val (street, state27) = state26.registerEntity(Street(0))
  val state28 = world.addChild(state27, street)

  val state29 = state28(MoveAction(kozlik, balaganchik, street))
  val state30 = state29(MoveAction(nezn, balaganchik, street))

  val state31 = street.map(state30, a => a.copy(temprature = -50))

  val state32 = state31(MoveAction(kozlik, street, canteen))
  val state33 = state32(MoveAction(nezn, street, canteen))



}
